package com.bw.gmallapi.controller;

import com.bw.gmallapi.pojo.Order;
import com.bw.gmallapi.service.IOrderService;
import com.bw.gmallapi.service.impl.OrderService;
import com.bw.gmallapi.util.DateFormatUtil;
import com.bw.gmallapi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/gmall/api")
@Slf4j
public class GmallController {

    @Autowired
    private IOrderService orderService;

    @RequestMapping("/test")
    public String getMsg(){
        return "123123";
    }

    @GetMapping("/test1")
    public String getMsg1(){
        return "456";
    }

    @RequestMapping("/gmv")
    public R<BigDecimal> getGmv(@RequestParam(value = "date",defaultValue = "0") String date){
        System.out.println("date = " + date);
        if ("0".equals(date)){
            date = DateFormatUtil.getNowDate();
        }
        BigDecimal gmv = orderService.getGmv(date);
        return R.success(gmv);
    }

    @RequestMapping("/getOrderList")
    public R<List<Order>> getOrderList(@RequestParam(value = "date",defaultValue = "0") String date){
        if ("0".equals(date)){
            date = DateFormatUtil.getNowDate();
        }
        List<Order> orderList = orderService.getOrderList(date);
        return R.success(orderList);
    }
}
